#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    int a[40001];
    scanf("%d",&n);
    for (int i=1;i<=n;i++) {
        scanf("%d",&a[i]);
    }
    int len=n;
    int score=0;
    while (len>1) {
        int minsum=401,minp1;
        for(int i=1;i<=len-1;i++) {
            if (a[i]+a[i+1]<minsum) {
                minsum=a[i]+a[i+1];
                minp1=i;
            }
        }
        score+=minsum;
        a[minp1]=minsum;
        for(int i=minp1+2;i<=len;i++) {
            a[i-1]=a[i];
        }
        a[len]=0;
        len--;
    }
    printf("%d",score);
    system("pause");
    return 0;
}